package com.atguigu.guli.service.edu.controller.api;


import com.atguigu.guli.service.base.result.R;
import com.atguigu.guli.service.edu.entity.Teacher;
import com.atguigu.guli.service.edu.service.TeacherService;
import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 讲师 前端控制器
 * </p>
 *
 * @author atguigu
 * @since 2021-10-26
 */
@RestController

@RequestMapping("/api/edu/teacher")
public class ApiTeacherController {
    @Autowired
    TeacherService teacherService;

    @GetMapping("list")
    public R list() {
        List<Teacher> list = teacherService.list();
        return R.ok().data("list",list);
    }
    @GetMapping("getTeacherById/{id}")
    public R getTeacherById(@PathVariable String id){
        Teacher teacher = teacherService.getById(id);
        return R.ok().data("item",teacher);
    }
    //查询热门讲师信息列表
    @GetMapping("getHotTeacher")
    public R getHotTeacher(){
        LambdaQueryWrapper<Teacher> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.orderByDesc(Teacher::getSort);
        queryWrapper.last("limit 0,4");
        List<Teacher> teacherList = teacherService.list(queryWrapper);
        return R.ok().data("items",teacherList);
    }

}

